package com.bysj.yqsht.service.impl;

import com.bysj.yqsht.bean.Tuition;
import com.bysj.yqsht.bean.TuitionExample;
import com.bysj.yqsht.bean.extend.TuitionExtend;
import com.bysj.yqsht.dao.TuitionMapper;
import com.bysj.yqsht.dao.extend.TuitionExtendMapper;
import com.bysj.yqsht.service.ITuitionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ITuitionServiceImpl implements ITuitionService {
    @Resource
    private TuitionMapper tuitionMapper;
    @Resource
    private TuitionExtendMapper tuitionExtendMapper;
    @Override
    public List<Tuition> findAll() {
        TuitionExample example = new TuitionExample();
        return tuitionMapper.selectByExample(example);
    }

    @Override
    public List<TuitionExtend> findWithAll(int pageNum, int limit) {
        PageHelper.startPage(pageNum,limit);
        TuitionExample example = new TuitionExample();
        List<TuitionExtend> list1 = tuitionExtendMapper.findWithAll();
        PageInfo<TuitionExtend> data = new PageInfo<TuitionExtend>(list1);
        List<TuitionExtend> list = data.getList();
        return list;
    }

    @Override
    public List<TuitionExtend> findWithAllBy(String status, Long studentId) {
        return tuitionExtendMapper.findWithAllBy(status,studentId);
    }

    @Override
    public void deleteById(long id) {
        tuitionMapper.deleteByPrimaryKey(id);

    }

    @Override
    public void saveOrUpdate(Tuition tuition) {
        if(tuition.getId() != null){
                tuitionMapper.updateByPrimaryKey(tuition);
        }else {
            tuitionMapper.insert(tuition);
        }

    }
}
